﻿@model KPIS.GERP.Models.ICM.Committee

@{
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
	ViewBag.Title = "แก้ไข " + (Model.CommitteeId.ToString() ?? string.Empty);
}

@using (Html.BeginForm("Edit", "Committee", FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()

    <div class="block-button-menu-above">
        @Html.ActionLink("กลับไปหน้าแสดงข้อมูลทั้งหมด", "Index", new { id = Model.CommitteeId, CommitteeGroupId = Model.CommitteeGroupId }, new { @class = "btn btn-gray button-standard-width btn-small", role="button" })
        @Html.ButtonSubmit()
        @Html.ButtonCancel(new { id = Model.CommitteeId })
    </div>
    
    @Html.ValidationSummary(true, KPIS.GERP.Models.Class.ValidateText.RequiredField, new { @class = "alert alert-error" })
    @Html.Partial("_EditForm")
}

@section scripts
{
    <script>
        $(function () {
            ChangeEnableComType();

            $('#ddlEmpId').change(function () {
                var id = $('#ddlEmpId').val();
                var text = $('#ddlEmpId').find(":selected").text();
                $('#txtEmpName').val(text);

                if (id != '') {
                    $.getJSON('@Url.Action("GetEmployeeDetails")/' + id, function (data) {
                        $("#txtEmpPositionName").val(data.Position.Name);
                    });
                }
            });

            if ($('#rbtComType0').is(':checked')) {
                $('#ddlEmpId').change();
            }
        });

        //$('#txtEmpName').attr('disabled', '');

        $('input[name=ComTypeId]').change(ChangeEnableComType);

        function ChangeEnableComType() {
            if ($('#rbtComType0').is(':checked')) {
                $('#txtEmpName').attr('readonly', '').val("");                
                $('#ddlEmpId').removeAttr('disabled').trigger("liszt:updated");
                $('#txtEmpPositionName').attr('disabled', 'disabled');
            } else {
                $('#ddlEmpId').attr('disabled', '').val("").trigger("liszt:updated");
                $('#txtEmpName').removeAttr('readonly');
                $('#txtEmpPositionName').removeAttr('disabled', 'disabled');
            }
        }

        $("form").submit(function (e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm(function (result) {
                if (result) {
                    currentForm.submit();
                }
            });
        });
    </script>
}